app_family.controller("controller_home", function($scope, $rootScope, httpRequest, $location) {
    $scope.imagebasepath = imagebasepath; // 资源图片根目录
    $rootScope.$broadcast('currentModule', 'page_home');
    $rootScope.$broadcast('footerFlag', true); // 是否显示底部导航

    // 初始化互动模式为群聊
    data_sessionStorage = JSON.parse(sessionStorage.getItem('data_sessionStorage'));

    /**
     * 判断是否用手机登录过
     */
    if (data_sessionStorage) {
        var familyPhone = data_sessionStorage.familyInfo.phone;
        if (familyPhone == '' || familyPhone == null) {
            window.location.replace(basepath + 'login.html');
            return;
        }
    } else {
        window.location.replace(basepath + 'login.html');
        return;
    }

    data_sessionStorage.chat.chatType = 'all';
    sessionStorage.setItem('data_sessionStorage', JSON.stringify(data_sessionStorage));

    data_sessionStorage = JSON.parse(sessionStorage.getItem('data_sessionStorage'));

    /**
     * slider
     */
    $scope.loadSlider = function(list) {
        var is = new iSlider({
            dom: document.getElementById('iSlider-wrapper'),
            data: list,
            isLooping: 1,
            isOverspread: 1,
            isAutoplay: true,
            animateTime: 800, // ms
            plugins: [
                ['dot', { locate: 'relative' }]
            ]
        });
    };

    /**
     * 加载代付订单
     */

    var data = {
        attributes: {
            orderList: [{
                icon: '',
                order_title: '科罗娜进口精酿啤酒',
                order_time: '2017-05-07 16:05:20',
                user_name: 'Miya',
                sumMoney: '99.00',
                exclusive_key: '1'
            }],
            pictureList: [{
                pictureUrl: basepath + 'resources/images/1494815867147973.jpg'
            }, {
                pictureUrl: basepath + 'resources/images/591181200166b.jpg'
            }],
            supplierList: [{
                icon: '',
                name: '江苏润和',
                provinceName: '江苏',
                cityName: '南京',
                countyName: '',
                address: '软件大道'
            }]
        }
    };

    // 代付订单
    $scope.orderlist_forPaying = data.attributes.orderList;
    $rootScope.$broadcast('orderforPayingNum', $scope.orderlist_forPaying.length); // 代付订单数量 显示在底部导航上

    // 幻灯片
    var list = [];
    for (var i = 0; i < data.attributes.pictureList.length; i++) {
        list.push({
            content: data.attributes.pictureList[i].pictureUrl
        });
    }
    $scope.loadSlider(list);

    // 养老机构
    $scope.supplierList = data.attributes.supplierList;



    /**
     * 订单操作 去支付
     */
    $scope.order_pay = function(order_id, exclusive_key) {
        $.dialog.showDialog({
            isShowTitle: true,
            titleTxt: '在线去支付',
            msgTxt: '<div class="alipay-wrap"><img height="50" src="' + basepath + 'resources/images/alipay.png" /></div>',
            isShowBtnCancel: true,
            callbackOk: function() {
                // 根据订单，生成支付宝支付链接信息

                var data = {
                    success: true,
                    obj: '',
                    msg: '成功！'
                };
                if (data.success === true) {
                    // 调用手机本地的支付宝应用  options:支付链接, 订单id, 排他key
                    var options = {
                        payLink: data.obj,
                        order_id: order_id,
                        exclusive_key: exclusive_key,
                        callback: 'javascript:angular.element(document.getElementById("controller_orderlist")).scope().getPayResult'
                    };
                    $.fn_native.type_android.goPay(JSON.stringify(options));
                } else if (data.success === false) {
                    $.dialog.showToast({ msgTxt: data.msg });
                }

            }
        });
        event.stopPropagation();
    };

    /**
     * 点击代付订单
     */
    $scope.toOrderlist = function() {
        // 指定订单列表显示代付订单的tab
        data_sessionStorage = JSON.parse(sessionStorage.getItem('data_sessionStorage'));
        data_sessionStorage.record_page.page_ordertype = '';
        sessionStorage.setItem('data_sessionStorage', JSON.stringify(data_sessionStorage));

        // 跳转到订单列表
        $location.path('/orderlist');
        $scope.$apply();
    };

    /**
     * 查看养老机构的详细信息
     */
    $scope.orgInfo = function(supplier_id) {
        // 记录要查看的养老机构的id
        data_sessionStorage = JSON.parse(sessionStorage.getItem('data_sessionStorage'));
        data_sessionStorage.recommend_org.supplier_id = supplier_id;
        sessionStorage.setItem('data_sessionStorage', JSON.stringify(data_sessionStorage));

        // 跳转到养老机构详细信息页面
        $location.path('/organizationinfo');
        $scope.$apply();
    };
});